package miniMax;

import java.util.ArrayList;
import java.util.List;

public final class Node {
	
	private static int counter = 0;
	
	private TicTacToeFramework ttt;
	private Node parent;
	private List<Node> children;
	private int value;
	private int ebene;
	private int id;
	private String nodeMaxMin;
	
	public Node(final Node parentP, int id, String mm) {
		setNodeMaxMin(mm);
		this.setId(id);
		this.setTtt(parentP.getTtt().getGameField());
		this.setParent(parentP);
		this.ebene = parentP.getEbene() + 1;
		children = new ArrayList<Node>();
//		System.out.println("Neuer Knoten");
//		System.out.println(this.ebene);
//		this.ttt.print();
//		System.out.println("___________");
		value = 1;
		counter++;
	}
	
	public Node(final String[][] strings) {
		this.setTtt(strings);
		this.setParent(null);
		children = new ArrayList<Node>();
		ebene = 1;
		counter++;
		nodeMaxMin = "Max";
	}
	

	public void addChild(Node child){
		children.add(child);
	}
	
	@Override
	public boolean equals(Object obj){
		Node node;
		if(obj instanceof Node){
			node = (Node) obj;
		}
		else {
			return false;
		}
		boolean tttEauqal = node.getTtt().equals(this.getTtt());
		return tttEauqal;
	}
	
	@Override
	public int hashCode(){
		int hashCodeOfttt = this.getTtt().hashCode(); 
		return hashCodeOfttt;
	}
	
//	@Override
//	public String toString(){
//		System.out.println("Ebene " + this.getEbene());
//		System.out.println("Bewertung: " + getValue());
//		this.ttt.print();
//		for (Node child : children) {
//			System.out.println("Kinder: ");
//			child.toString();
//		}
//		return "Number of Nodes: " + counter;
//	}
	public List<Node> returnChildren() {
		return children;
	}

	public TicTacToeFramework getTtt() {
		return ttt;
	}

	public void setTtt(final String[][] strings) {
		this.ttt = new TicTacToeFramework();
		this.ttt.setGameField(strings);
	}

	public int getValue() {
		return value;
	}

	public void setValue(final int value) {
		this.value = value;
	}

	public Node getParent() {
		return parent;
	}

	public void setParent(final Node parent) {
		this.parent = parent;
	}

	public int getEbene() {
		return ebene;
	}

	public void setEbene(final int ebene) {
		this.ebene = ebene;
	}

	public int getId() {
		return id;
	}

	public void setId(final int id) {
		this.id = id;
	}

	public String getNodeMaxMin() {
		return nodeMaxMin;
	}

	public void setNodeMaxMin(String nodeMaxMin) {
		this.nodeMaxMin = nodeMaxMin;
	}
	
}
